#include <stdio.h>
#define maxn 200000
int n,a[maxn],s[maxn];
int lowbit(int x)
{
    return x&(-x);
}
void modify(int pos,int val)
{
    while(pos<=n)
    {
        s[pos]+=val;
        pos+=lowbit(pos);
    }
}
int query(int end)
{
    int sum=0;
    while(end>0)
    {
        {
            sum+=s[end];
            end-=lowbit(end);
        }
    }
    return sum;
}
int main()
{
    int i,j,k,ans;
    while(scanf("%d",&n)!=EOF)
    {
        for(i=1;i<=n;i++)
        s[i]=0;
        ans=0;
        for(i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            modify(a[i],1);
            ans=(ans+(__int64_t)(query(a[i]-1)*(__int64_t)((n-a[i])-(i-query(a[i])))))%10000007;
        }
        printf("%d\n",ans);
    }
    return 0;
}
